package cn.marinda.totipotentwar.runnable;

import cn.marinda.totipotentwar.TotipotentWar;
import cn.marinda.totipotentwar.global.GameData;
import cn.marinda.totipotentwar.manager.GameDataManager;
import cn.marinda.totipotentwar.utils.GameUtil;
import cn.marinda.totipotentwar.utils.TimeUtil;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;

public class DelayMoveRunnable extends BukkitRunnable {
    /**
     * 延迟转移可运行
     */
    public DelayMoveRunnable()
    {
    }
    /**
     * When an object implementing interface <code>Runnable</code> is used
     * to create a thread, starting the thread causes the object's
     * <code>run</code> method to be called in that separately executing
     * thread.
     * <p>
     * The general contract of the method <code>run</code> is that it may
     * take any action whatsoever.
     *
     * @see Thread#run()
     */
    @Override
    public void run() {
        GameDataManager gameDataManager = TotipotentWar.gameDataManager;

        /**
         * When an object implementing interface <code>Runnable</code> is used
         * to create a thread, starting the thread causes the object's
         * <code>run</code> method to be called in that separately executing
         * thread.
         * <p>
         * The general contract of the method <code>run</code> is that it may
         * take any action whatsoever.
         *
         * @see Thread#run()
         */
        if(GameUtil.startFlag){
            GameUtil.delaySecond++;
            int delay = TimeUtil.delayTime(3);
            if(GameUtil.delaySecond == delay){
                cancel();
                GameUtil.delayFlag = true;
            }
            //设置提示消息！
            for(Player player : GameUtil.playerGame){
                player.sendTitle("§a还差：§c" +(delay - GameUtil.delaySecond) + "§a秒§e才能行动","§6游戏准备开始",20,20,20) ;
                //初始化
                gameDataManager.putGameData(player.getUniqueId().toString(),new GameData(player,0,0,1));
            }
        }

    }
}
